package com.comp437.uno.view.playboard;

import java.lang.reflect.Field;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

import com.comp437.uno.model.Model;

public class Card extends ImageButton{
	String cardValue;
	protected int cardImage;
	int id; 
	static Model model;
	public Card(Context context) {
		super(context);
		model = Model.getModel();
	}
	
	public Card setCard(String cardValue, int id){
		this.cardValue = cardValue;
		this.id=id;
		 try {
				Field field = this.getClass().getField(cardValue);
				
				cardImage=field.getInt(this);
			} catch (NoSuchFieldException e) {
				
				e.printStackTrace();
			}

			 catch (IllegalArgumentException e) {
		
				e.printStackTrace();
			} catch (IllegalAccessException e) {

				e.printStackTrace();
			} 
			 this.setBackgroundResource(cardImage);
			 this.setOnClickListener(new bt_playListener());
			 return this;
	}
	
	public void setEnable(boolean a){
		super.setEnabled(a);
		//Log.i("Card","The enable function called "+a);
		if(a){
		
			this.setOnClickListener(new bt_playListener());
		}
		else{
		
			this.setEnabled(false);
			this.setOnClickListener(null);
		}
		
	}
	
	class bt_playListener implements android.view.View.OnClickListener {
		public bt_playListener(){
	
		}
		public void onClick(View v) {
				if(model.playCard(cardValue)){
					PlayBoard.removeCard(id);
				}
		}
	}
	
	
    public final int b0=0x7f020000;
    public final int b1=0x7f020001;
    public final int b2=0x7f020002;
    public final int b3=0x7f020003;
    public final int b4=0x7f020004;
    public final int b5=0x7f020005;
    public final int b6=0x7f020006;
    public final int b7=0x7f020007;
    public final int b8=0x7f020008;
    public final int b9=0x7f020009;
    public final int back=0x7f02000a;
    public final int background=0x7f02000b;
    public final int bd=0x7f02000c;
    public final int br=0x7f02000d;
    public final int bs=0x7f02000e;
    public final int g0=0x7f02000f;
    public final int g1=0x7f020010;
    public final int g2=0x7f020011;
    public final int g3=0x7f020012;
    public final int g4=0x7f020013;
    public final int g5=0x7f020014;
    public final int g6=0x7f020015;
    public final int g7=0x7f020016;
    public final int g8=0x7f020017;
    public final int g9=0x7f020018;
    public final int gd=0x7f020019;
    public final int gr=0x7f02001a;
    public final int gs=0x7f02001b;
    public final int icon_user=0x7f02001c;
    public final int inputbackground=0x7f02001d;
    public final int join=0x7f02001e;
    public final int login_bg=0x7f02001f;
    public final int lose=0x7f020020;
    public final int nojoin=0x7f020021;
    public final int profile_bg=0x7f020022;
    public final int r0=0x7f020023;
    public final int r1=0x7f020024;
    public final int r2=0x7f020025;
    public final int r3=0x7f020026;
    public final int r4=0x7f020027;
    public final int r5=0x7f020028;
    public final int r6=0x7f020029;
    public final int r7=0x7f02002a;
    public final int r8=0x7f02002b;
    public final int r9=0x7f02002c;
    public final int rd=0x7f02002d;
    public final int roombackground=0x7f02002e;
    public final int rr=0x7f02002f;
    public final int rs=0x7f020030;
    public final int settings=0x7f020031;
    public final int tab_bg=0x7f020032;
    public final int uno=0x7f020033;
    public final int uno_icon=0x7f020034;
    public final int uno_icon_lunchar=0x7f020035;
    public final int user1=0x7f020036;
    public final int user2=0x7f020037;
    public final int user_smile=0x7f020038;
    public final int win=0x7f020039;
    public final int y0=0x7f02003a;
    public final int y1=0x7f02003b;
    public final int y2=0x7f02003c;
    public final int y3=0x7f02003d;
    public final int y4=0x7f02003e;
    public final int y5=0x7f02003f;
    public final int y6=0x7f020040;
    public final int y7=0x7f020041;
    public final int y8=0x7f020042;
    public final int y9=0x7f020043;
    public final int yd=0x7f020044;
    public final int yr=0x7f020045;
    public final int ys=0x7f020046;
}
